let main_box = document.querySelector("#main_box");

const xhr1 = new XMLHttpRequest();
xhr1.open("get","http://chst.vip:1234/api/getcoupon",true);
xhr1.onload = function(){
    if(xhr1.status === 200){
        let res1 = JSON.parse(xhr1.responseText);
        console.log(res1);
        console.log(res1.result);

        let main_boxs = "";
        res1.result.forEach(item => {
            main_boxs += `<a href="../html/couponproduct.html?couponid=${item.couponId}">
                            <div class="coupon">
                            <img src="${item.couponImg}">
                                <p>${item.couponTitle}</p>
                            </div>
                        </a>`
            
        });
        main_box.innerHTML = main_boxs;

        // let aLi = document.querySelectorAll("#main_box ul li");
        // console.log(aLi);

        // aLi.forEach(index => {
        //     index.onclick = function(){
        //         let ID = index.id;
        //         console.log(ID);
        //         location.href = '../html/couponproduct.html?couponid='+ ID
        //     }
        // })

    }
}
xhr1.send(null);

